import React, { Component } from 'react'
import {browserHistory} from "react-router"


let BarStyle = {
        fontSize:"18px",
        textAlign:"center",
        width:"100%",
        height:"44px",
        lineHeight:"44px",
        position:"fixed",
        top:"0px",
        zIndex:"999999",
        backgroundColor:"#696969"
        //top:"0px"
};

export default class  NavigationBar extends  Component{
    constructor(props){
        super(props);

        this._backBtnClicked = this._backBtnClicked.bind(this);
    }


    componentWillMount(){

    }
    _backBtnClicked(){
        if(this.props.clickFunc){//自己指定了点击代码
            //console.log('called');
            this.props.clickFunc();
        }else if(this.props.BackURL == "0")
            window.history.go(-1);
        else
            browserHistory.push(this.props.BackURL);
    }
    getLeftBar()
    {
        if(this.props.LeftBar == "false")
            return "";
        else {

            //return <NavigationBarItem Position="left" BackURL={this.props.BackURL}/>
            return  <div style={LeftStyle} onClick={this._backBtnClicked}>
                <img style={{width:"44px",height:"44px"}} src="/public/img/icon_back.png"/>
            </div>
        }

    }






    render(){

        let leftbar  = this.getLeftBar() ;

        return (
            <div id="navigationBar" style={{width:"100%",height:"44px"}}>
                <div style={BarStyle}>
                    {leftbar}
                    <div style={{width:"60%",marginLeft:"20%",marginRight:"20%",overflow:"hidden",textOverflow:"ellipsis",color:"white"}}>{this.props.Title}</div>
                </div>
            </div>
        )
    }
}
let LeftStyle = {
    position:"absolute",
    left:"2.4%",
    height:"100%",
    width: "7%",
    textAlign: "left"

}
NavigationBar.defaultProps = {
    Title: "超值抢",
    LeftBar:"false",
    RightBar:"false",
    BackURL:"0"
}

NavigationBar.propTypes = {
    Title: React.PropTypes.string,
    LeftBar:React.PropTypes.string,
    RightBar:React.PropTypes.string,
    RightType:React.PropTypes.string,
    RightClick:React.PropTypes.func,
    BackURL:React.PropTypes.string,
}